home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / bison / bisn119s.zoo / bison.info-4 < prev    next >
Encoding:
GNU Info File  |  1992-09-05  |  37.4 KB  |  960 lines

  1. This is Info file bison.info, produced by Makeinfo-1.47 from the input
  2. file /home/gd/gnu/bison/bison.texinfo.
  3.  
  4.    This file documents the Bison parser generator.
  5.  
  6.    Copyright (C) 1988, 1989, 1990 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided also
  14. that the sections entitled "GNU General Public License" and "Conditions
  15. for Using Bison" are included exactly as in the original, and provided
  16. that the entire resulting derived work is distributed under the terms
  17. of a permission notice identical to this one.
  18.  
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that the sections entitled "GNU General Public
  22. License", "Conditions for Using Bison" and this permission notice may be
  23. included in translations approved by the Free Software Foundation
  24. instead of in the original English.
  25.  
  26. File: bison.info,  Node: Semantic Tokens,  Next: Lexical Tie-ins,  Prev: Context Dependency,  Up: Context Dependency
  27.  
  28. Semantic Info in Token Types
  29. ============================
  30.  
  31.    The C language has a context dependency: the way an identifier is
  32. used depends on what its current meaning is.  For example, consider
  33. this:
  34.  
  35.      foo (x);
  36.  
  37.    This looks like a function call statement, but if `foo' is a typedef
  38. name, then this is actually a declaration of `x'.  How can a Bison
  39. parser for C decide how to parse this input?
  40.  
  41.    The method used in GNU C is to have two different token types,
  42. `IDENTIFIER' and `TYPENAME'.  When `yylex' finds an identifier, it
  43. looks up the current declaration of the identifier in order to decide
  44. which token type to return: `TYPENAME' if the identifier is declared as
  45. a typedef, `IDENTIFIER' otherwise.
  46.  
  47.    The grammar rules can then express the context dependency by the
  48. choice of token type to recognize.  `IDENTIFIER' is accepted as an
  49. expression, but `TYPENAME' is not.  `TYPENAME' can start a declaration,
  50. but `IDENTIFIER' cannot.  In contexts where the meaning of the
  51. identifier is *not* significant, such as in declarations that can
  52. shadow a typedef name, either `TYPENAME' or `IDENTIFIER' is
  53. accepted--there is one rule for each of the two token types.
  54.  
  55.    This technique is simple to use if the decision of which kinds of
  56. identifiers to allow is made at a place close to where the identifier is
  57. parsed.  But in C this is not always so: C allows a declaration to
  58. redeclare a typedef name provided an explicit type has been specified
  59. earlier:
  60.  
  61.      typedef int foo, bar, lose;
  62.      static foo (bar);        /* redeclare `bar' as static variable */
  63.      static int foo (lose);   /* redeclare `foo' as function */
  64.  
  65.    Unfortunately, the name being declared is separated from the
  66. declaration construct itself by a complicated syntactic structure--the
  67. "declarator".
  68.  
  69.    As a result, the part of Bison parser for C needs to be duplicated,
  70. with all the nonterminal names changed: once for parsing a declaration
  71. in which a typedef name can be redefined, and once for parsing a
  72. declaration in which that can't be done.  Here is a part of the
  73. duplication, with actions omitted for brevity:
  74.  
  75.      initdcl:
  76.                declarator maybeasm '='
  77.                init
  78.              | declarator maybeasm
  79.              ;
  80.      
  81.      notype_initdcl:
  82.                notype_declarator maybeasm '='
  83.                init
  84.              | notype_declarator maybeasm
  85.              ;
  86.  
  87. Here `initdcl' can redeclare a typedef name, but `notype_initdcl'
  88. cannot.  The distinction between `declarator' and `notype_declarator'
  89. is the same sort of thing.
  90.  
  91.    There is some similarity between this technique and a lexical tie-in
  92. (described next), in that information which alters the lexical analysis
  93. is changed during parsing by other parts of the program.  The
  94. difference is here the information is global, and is used for other
  95. purposes in the program.  A true lexical tie-in has a special-purpose
  96. flag controlled by the syntactic context.
  97.  
  98. File: bison.info,  Node: Lexical Tie-ins,  Next: Tie-in Recovery,  Prev: Semantic Tokens,  Up: Context Dependency
  99.  
  100. Lexical Tie-ins
  101. ===============
  102.  
  103.    One way to handle context-dependency is the "lexical tie-in": a flag
  104. which is set by Bison actions, whose purpose is to alter the way tokens
  105. are parsed.
  106.  
  107.    For example, suppose we have a language vaguely like C, but with a
  108. special construct `hex (HEX-EXPR)'.  After the keyword `hex' comes an
  109. expression in parentheses in which all integers are hexadecimal.  In
  110. particular, the token `a1b' must be treated as an integer rather than
  111. as an identifier if it appears in that context.  Here is how you can do
  112. it:
  113.  
  114.      %{
  115.      int hexflag;
  116.      %}
  117.      %%
  118.      ...
  119.      expr:   IDENTIFIER
  120.              | constant
  121.              | HEX '('
  122.                      { hexflag = 1; }
  123.                expr ')'
  124.                      { hexflag = 0;
  125.                         $$ = $4; }
  126.              | expr '+' expr
  127.                      { $$ = make_sum ($1, $3); }
  128.              ...
  129.              ;
  130.      
  131.      constant:
  132.                INTEGER
  133.              | STRING
  134.              ;
  135.  
  136. Here we assume that `yylex' looks at the value of `hexflag'; when it is
  137. nonzero, all integers are parsed in hexadecimal, and tokens starting
  138. with letters are parsed as integers if possible.
  139.  
  140.    The declaration of `hexflag' shown in the C declarations section of
  141. the parser file is needed to make it accessible to the actions (*note C
  142. Declarations::.).  You must also write the code in `yylex' to obey the
  143. flag.
  144.  
  145. File: bison.info,  Node: Tie-in Recovery,  Prev: Lexical Tie-ins,  Up: Context Dependency
  146.  
  147. Lexical Tie-ins and Error Recovery
  148. ==================================
  149.  
  150.    Lexical tie-ins make strict demands on any error recovery rules you
  151. have. *Note Error Recovery::.
  152.  
  153.    The reason for this is that the purpose of an error recovery rule is
  154. to abort the parsing of one construct and resume in some larger
  155. construct. For example, in C-like languages, a typical error recovery
  156. rule is to skip tokens until the next semicolon, and then start a new
  157. statement, like this:
  158.  
  159.      stmt:   expr ';'
  160.              | IF '(' expr ')' stmt { ... }
  161.              ...
  162.              error ';'
  163.                      { hexflag = 0; }
  164.              ;
  165.  
  166.    If there is a syntax error in the middle of a `hex (EXPR)'
  167. construct, this error rule will apply, and then the action for the
  168. completed `hex (EXPR)' will never run.  So `hexflag' would remain set
  169. for the entire rest of the input, or until the next `hex' keyword,
  170. causing identifiers to be misinterpreted as integers.
  171.  
  172.    To avoid this problem the error recovery rule itself clears
  173. `hexflag'.
  174.  
  175.    There may also be an error recovery rule that works within
  176. expressions. For example, there could be a rule which applies within
  177. parentheses and skips to the close-parenthesis:
  178.  
  179.      expr:   ...
  180.              | '(' expr ')'
  181.                      { $$ = $2; }
  182.              | '(' error ')'
  183.              ...
  184.  
  185.    If this rule acts within the `hex' construct, it is not going to
  186. abort that construct (since it applies to an inner level of parentheses
  187. within the construct).  Therefore, it should not clear the flag: the
  188. rest of the `hex' construct should be parsed with the flag still in
  189. effect.
  190.  
  191.    What if there is an error recovery rule which might abort out of the
  192. `hex' construct or might not, depending on circumstances?  There is no
  193. way you can write the action to determine whether a `hex' construct is
  194. being aborted or not.  So if you are using a lexical tie-in, you had
  195. better make sure your error recovery rules are not of this kind.  Each
  196. rule must be such that you can be sure that it always will, or always
  197. won't, have to clear the flag.
  198.  
  199. File: bison.info,  Node: Debugging,  Next: Invocation,  Prev: Context Dependency,  Up: Top
  200.  
  201. Debugging Your Parser
  202. *********************
  203.  
  204.    If a Bison grammar compiles properly but doesn't do what you want
  205. when it runs, the `yydebug' parser-trace feature can help you figure
  206. out why.
  207.  
  208.    To enable compilation of trace facilities, you must define the macro
  209. `YYDEBUG' when you compile the parser.  You could use `-DYYDEBUG=1' as
  210. a compiler option or you could put `#define YYDEBUG 1' in the C
  211. declarations section of the grammar file (*note C Declarations::.). 
  212. Alternatively, use the `-t' option when you run Bison (*note
  213. Invocation::.).  We always define `YYDEBUG' so that debugging is always
  214. possible.
  215.  
  216.    The trace facility uses `stderr', so you must add
  217. `#include <stdio.h>' to the C declarations section unless it is already
  218. there.
  219.  
  220.    Once you have compiled the program with trace facilities, the way to
  221. request a trace is to store a nonzero value in the variable `yydebug'.
  222. You can do this by making the C code do it (in `main', perhaps), or you
  223. can alter the value with a C debugger.
  224.  
  225.    Each step taken by the parser when `yydebug' is nonzero produces a
  226. line or two of trace information, written on `stderr'.  The trace
  227. messages tell you these things:
  228.  
  229.    * Each time the parser calls `yylex', what kind of token was read.
  230.  
  231.    * Each time a token is shifted, the depth and complete contents of
  232.      the state stack (*note Parser States::.).
  233.  
  234.    * Each time a rule is reduced, which rule it is, and the complete
  235.      contents of the state stack afterward.
  236.  
  237.    To make sense of this information, it helps to refer to the listing
  238. file produced by the Bison `-v' option (*note Invocation::.).  This file
  239. shows the meaning of each state in terms of positions in various rules,
  240. and also what each state will do with each possible input token.  As
  241. you read the successive trace messages, you can see that the parser is
  242. functioning according to its specification in the listing file. 
  243. Eventually you will arrive at the place where something undesirable
  244. happens, and you will see which parts of the grammar are to blame.
  245.  
  246.    The parser file is a C program and you can use C debuggers on it,
  247. but it's not easy to interpret what it is doing.  The parser function
  248. is a finite-state machine interpreter, and aside from the actions it
  249. executes the same code over and over.  Only the values of variables
  250. show where in the grammar it is working.
  251.  
  252.    The debugging information normally gives the token type of each token
  253. read, but not its semantic value.  You can optionally define a macro
  254. named `YYPRINT' to provide a way to print the value.  If you define
  255. `YYPRINT', it should take three arguments.  The parser will pass a
  256. standard I/O stream, the numeric code for the token type, and the token
  257. value (from `yylval').
  258.  
  259.    Here is an example of `YYPRINT' suitable for the multi-function
  260. calculator (*note Mfcalc Decl::.):
  261.  
  262.      #define YYPRINT(file, type, value)   yyprint (file, type, value)
  263.      
  264.      static void
  265.      yyprint (file, type, value)
  266.           FILE *file;
  267.           int type;
  268.           YYSTYPE value;
  269.      {
  270.        if (type == VAR)
  271.          fprintf (file, " %s", value.tptr->name);
  272.        else if (type == NUM)
  273.          fprintf (file, " %d", value.val);
  274.      }
  275.  
  276. File: bison.info,  Node: Invocation,  Next: Table of Symbols,  Prev: Debugging,  Up: Top
  277.  
  278. Invoking Bison
  279. **************
  280.  
  281.    The usual way to invoke Bison is as follows:
  282.  
  283.      bison INFILE
  284.  
  285.    Here INFILE is the grammar file name, which usually ends in `.y'. 
  286. The parser file's name is made by replacing the `.y' with `.tab.c'. 
  287. Thus, the `bison foo.y' filename yields `foo.tab.c', and the `bison
  288. hack/foo.y' filename yields `hack/foo.tab.c'.
  289.  
  290. * Menu:
  291.  
  292. * Bison Options::    All the options described in detail,
  293.               in alphabetical order by short options.
  294. * Option Cross Key::    Alphabetical list of long options.
  295. * VMS Invocation::    Bison command syntax on VMS.
  296.  
  297. File: bison.info,  Node: Bison Options,  Next: Option Cross Key,  Up: Invocation
  298.  
  299. Bison Options
  300. =============
  301.  
  302.    Bison supports both traditional single-letter options and mnemonic
  303. long option names.  Long option names are indicated with `--' instead of
  304. `-'.  Abbreviations for option names are allowed as long as they are
  305. unique.  When a long option takes an argument, like `--file-prefix',
  306. connect the option name and the argument with `='.
  307.  
  308.    Here is a list of options that can be used with Bison, alphabetized
  309. by short option.  It is followed by a cross key alphabetized by long
  310. option.
  311.  
  312. `-b FILE-PREFIX'
  313. `--file-prefix=PREFIX'
  314.      Specify a prefix to use for all Bison output file names.  The
  315.      names are chosen as if the input file were named `PREFIX.c'.
  316.  
  317. `-d'
  318. `--defines'
  319.      Write an extra output file containing macro definitions for the
  320.      token type names defined in the grammar and the semantic value type
  321.      `YYSTYPE', as well as a few `extern' variable declarations.
  322.  
  323.      If the parser output file is named `NAME.c' then this file is
  324.      named `NAME.h'.
  325.  
  326.      This output file is essential if you wish to put the definition of
  327.      `yylex' in a separate source file, because `yylex' needs to be
  328.      able to refer to token type codes and the variable `yylval'. 
  329.      *Note Token Values::.
  330.  
  331. `-l'
  332. `--no-lines'
  333.      Don't put any `#line' preprocessor commands in the parser file.
  334.      Ordinarily Bison puts them in the parser file so that the C
  335.      compiler and debuggers will associate errors with your source
  336.      file, the grammar file.  This option causes them to associate
  337.      errors with the parser file, treating it an independent source
  338.      file in its own right.
  339.  
  340. `-o OUTFILE'
  341. `--output-file=OUTFILE'
  342.      Specify the name OUTFILE for the parser file.
  343.  
  344.      The other output files' names are constructed from OUTFILE as
  345.      described under the `-v' and `-d' switches.
  346.  
  347. `-p PREFIX'
  348. `--name-prefix=PREFIX'
  349.      Rename the external symbols used in the parser so that they start
  350.      with PREFIX instead of `yy'.  The precise list of symbols renamed
  351.      is `yyparse', `yylex', `yyerror', `yylval', `yychar' and `yydebug'.
  352.  
  353.      For example, if you use `-p c', the names become `cparse', `clex',
  354.      and so on.
  355.  
  356.      *Note Multiple Parsers::.
  357.  
  358. `-t'
  359. `--debug'
  360.      Output a definition of the macro `YYDEBUG' into the parser file,
  361.      so that the debugging facilities are compiled.  *Note Debugging::.
  362.  
  363. `-v'
  364. `--verbose'
  365.      Write an extra output file containing verbose descriptions of the
  366.      parser states and what is done for each type of look-ahead token in
  367.      that state.
  368.  
  369.      This file also describes all the conflicts, both those resolved by
  370.      operator precedence and the unresolved ones.
  371.  
  372.      The file's name is made by removing `.tab.c' or `.c' from the
  373.      parser output file name, and adding `.output' instead.
  374.  
  375.      Therefore, if the input file is `foo.y', then the parser file is
  376.      called `foo.tab.c' by default.  As a consequence, the verbose
  377.      output file is called `foo.output'.
  378.  
  379. `-V'
  380. `--version'
  381.      Print the version number of Bison.
  382.  
  383. `-y'
  384. `--yacc'
  385. `--fixed-output-files'
  386.      Equivalent to `-o y.tab.c'; the parser output file is called
  387.      `y.tab.c', and the other outputs are called `y.output' and
  388.      `y.tab.h'.  The purpose of this switch is to imitate Yacc's output
  389.      file name conventions.  Thus, the following shell script can
  390.      substitute for Yacc:
  391.  
  392.           bison -y $*
  393.  
  394. File: bison.info,  Node: Option Cross Key,  Next: VMS Invocation,  Prev: Bison Options,  Up: Invocation
  395.  
  396. Option Cross Key
  397. ================
  398.  
  399.    Here is a list of options, alphabetized by long option, to help you
  400. find the corresponding short option.
  401.  
  402.      --debug                               -t
  403.      --defines                             -d
  404.      --file-prefix=PREFIX                  -b FILE-PREFIX
  405.      --fixed-output-files --yacc           -y
  406.      --name-prefix                         -p
  407.      --no-lines                            -l
  408.      --output-file=OUTFILE                 -o OUTFILE
  409.      --verbose                             -v
  410.      --version                             -V
  411.  
  412. File: bison.info,  Node: VMS Invocation,  Prev: Option Cross Key,  Up: Invocation
  413.  
  414. Invoking Bison under VMS
  415. ========================
  416.  
  417.    The command line syntax for Bison on VMS is a variant of the usual
  418. Bison command syntax--adapted to fit VMS conventions.
  419.  
  420.    To find the VMS equivalent for any Bison option, start with the long
  421. option, and substitute a `/' for the leading `--', and substitute a `_'
  422. for each `-' in the name of the long option. For example, the following
  423. invocation under VMS:
  424.  
  425.      bison /debug/name_prefix=bar foo.y
  426.  
  427.    is equivalent to the following command under POSIX.
  428.  
  429.      bison --debug --name-prefix=bar foo.y
  430.  
  431.    The VMS filesystem does not permit filenames such as `foo.tab.c'. 
  432. In the above example, the output file would instead be named
  433. `foo_tab.c'.
  434.  
  435. File: bison.info,  Node: Table of Symbols,  Next: Glossary,  Prev: Invocation,  Up: Top
  436.  
  437. Bison Symbols
  438. *************
  439.  
  440. `error'
  441.      A token name reserved for error recovery.  This token may be used
  442.      in grammar rules so as to allow the Bison parser to recognize an
  443.      error in the grammar without halting the process.  In effect, a
  444.      sentence containing an error may be recognized as valid.  On a
  445.      parse error, the token `error' becomes the current look-ahead
  446.      token.  Actions corresponding to `error' are then executed, and
  447.      the look-ahead token is reset to the token that originally caused
  448.      the violation. *Note Error Recovery::.
  449.  
  450. `YYABORT'
  451.      Macro to pretend that an unrecoverable syntax error has occurred,
  452.      by making `yyparse' return 1 immediately.  The error reporting
  453.      function `yyerror' is not called.  *Note Parser Function::.
  454.  
  455. `YYACCEPT'
  456.      Macro to pretend that a complete utterance of the language has been
  457.      read, by making `yyparse' return 0 immediately.  *Note Parser
  458.      Function::.
  459.  
  460. `YYBACKUP'
  461.      Macro to discard a value from the parser stack and fake a
  462.      look-ahead token.  *Note Action Features::.
  463.  
  464. `YYERROR'
  465.      Macro to pretend that a syntax error has just been detected: call
  466.      `yyerror' and then perform normal error recovery if possible
  467.      (*note Error Recovery::.), or (if recovery is impossible) make
  468.      `yyparse' return 1.  *Note Error Recovery::.
  469.  
  470. `YYINITDEPTH'
  471.      Macro for specifying the initial size of the parser stack. *Note
  472.      Stack Overflow::.
  473.  
  474. `YYLTYPE'
  475.      Macro for the data type of `yylloc'; a structure with four
  476.      members.  *Note Token Positions::.
  477.  
  478. `YYMAXDEPTH'
  479.      Macro for specifying the maximum size of the parser stack. *Note
  480.      Stack Overflow::.
  481.  
  482. `YYRECOVERING'
  483.      Macro whose value indicates whether the parser is recovering from a
  484.      syntax error.  *Note Action Features::.
  485.  
  486. `YYSTYPE'
  487.      Macro for the data type of semantic values; `int' by default.
  488.      *Note Value Type::.
  489.  
  490. `yychar'
  491.      External integer variable that contains the integer value of the
  492.      current look-ahead token.  (In a pure parser, it is a local
  493.      variable within `yyparse'.)  Error-recovery rule actions may
  494.      examine this variable.  *Note Action Features::.
  495.  
  496. `yyclearin'
  497.      Macro used in error-recovery rule actions.  It clears the previous
  498.      look-ahead token.  *Note Error Recovery::.
  499.  
  500. `yydebug'
  501.      External integer variable set to zero by default.  If `yydebug' is
  502.      given a nonzero value, the parser will output information on input
  503.      symbols and parser action.  *Note Debugging::.
  504.  
  505. `yyerrok'
  506.      Macro to cause parser to recover immediately to its normal mode
  507.      after a parse error.  *Note Error Recovery::.
  508.  
  509. `yyerror'
  510.      User-supplied function to be called by `yyparse' on error.  The
  511.      function receives one argument, a pointer to a character string
  512.      containing an error message.  *Note Error Reporting::.
  513.  
  514. `yylex'
  515.      User-supplied lexical analyzer function, called with no arguments
  516.      to get the next token.  *Note Lexical::.
  517.  
  518. `yylval'
  519.      External variable in which `yylex' should place the semantic value
  520.      associated with a token.  (In a pure parser, it is a local
  521.      variable within `yyparse', and its address is passed to `yylex'.) 
  522.      *Note Token Values::.
  523.  
  524. `yylloc'
  525.      External variable in which `yylex' should place the line and
  526.      column numbers associated with a token.  (In a pure parser, it is a
  527.      local variable within `yyparse', and its address is passed to
  528.      `yylex'.)  You can ignore this variable if you don't use the `@'
  529.      feature in the grammar actions.  *Note Token Positions::.
  530.  
  531. `yynerrs'
  532.      Global variable which Bison increments each time there is a parse
  533.      error.  (In a pure parser, it is a local variable within
  534.      `yyparse'.)  *Note Error Reporting::.
  535.  
  536. `yyparse'
  537.      The parser function produced by Bison; call this function to start
  538.      parsing.  *Note Parser Function::.
  539.  
  540. `%left'
  541.      Bison declaration to assign left associativity to token(s). *Note
  542.      Precedence Decl::.
  543.  
  544. `%nonassoc'
  545.      Bison declaration to assign nonassociativity to token(s). *Note
  546.      Precedence Decl::.
  547.  
  548. `%prec'
  549.      Bison declaration to assign a precedence to a specific rule. *Note
  550.      Contextual Precedence::.
  551.  
  552. `%pure_parser'
  553.      Bison declaration to request a pure (reentrant) parser. *Note Pure
  554.      Decl::.
  555.  
  556. `%right'
  557.      Bison declaration to assign right associativity to token(s). *Note
  558.      Precedence Decl::.
  559.  
  560. `%start'
  561.      Bison declaration to specify the start symbol.  *Note Start Decl::.
  562.  
  563. `%token'
  564.      Bison declaration to declare token(s) without specifying
  565.      precedence. *Note Token Decl::.
  566.  
  567. `%type'
  568.      Bison declaration to declare nonterminals.  *Note Type Decl::.
  569.  
  570. `%union'
  571.      Bison declaration to specify several possible data types for
  572.      semantic values.  *Note Union Decl::.
  573.  
  574.    These are the punctuation and delimiters used in Bison input:
  575.  
  576. `%%'
  577.      Delimiter used to separate the grammar rule section from the Bison
  578.      declarations section or the additional C code section. *Note
  579.      Grammar Layout::.
  580.  
  581. `%{ %}'
  582.      All code listed between `%{' and `%}' is copied directly to the
  583.      output file uninterpreted.  Such code forms the "C declarations"
  584.      section of the input file.  *Note Grammar Outline::.
  585.  
  586. `/*...*/'
  587.      Comment delimiters, as in C.
  588.  
  589. `:'
  590.      Separates a rule's result from its components.  *Note Rules::.
  591.  
  592. `;'
  593.      Terminates a rule.  *Note Rules::.
  594.  
  595. `|'
  596.      Separates alternate rules for the same result nonterminal. *Note
  597.      Rules::.
  598.  
  599. File: bison.info,  Node: Glossary,  Next: Index,  Prev: Table of Symbols,  Up: top
  600.  
  601. Glossary
  602. ********
  603.  
  604. Backus-Naur Form (BNF)
  605.      Formal method of specifying context-free grammars.  BNF was first
  606.      used in the `ALGOL-60' report, 1963.  *Note Language and Grammar::.
  607.  
  608. Context-free grammars
  609.      Grammars specified as rules that can be applied regardless of
  610.      context. Thus, if there is a rule which says that an integer can
  611.      be used as an expression, integers are allowed *anywhere* an
  612.      expression is permitted.  *Note Language and Grammar::.
  613.  
  614. Dynamic allocation
  615.      Allocation of memory that occurs during execution, rather than at
  616.      compile time or on entry to a function.
  617.  
  618. Empty string
  619.      Analogous to the empty set in set theory, the empty string is a
  620.      character string of length zero.
  621.  
  622. Finite-state stack machine
  623.      A "machine" that has discrete states in which it is said to exist
  624.      at each instant in time.  As input to the machine is processed, the
  625.      machine moves from state to state as specified by the logic of the
  626.      machine.  In the case of the parser, the input is the language
  627.      being parsed, and the states correspond to various stages in the
  628.      grammar rules.  *Note Algorithm::.
  629.  
  630. Grouping
  631.      A language construct that is (in general) grammatically divisible;
  632.      for example, `expression' or `declaration' in C.  *Note Language
  633.      and Grammar::.
  634.  
  635. Infix operator
  636.      An arithmetic operator that is placed between the operands on
  637.      which it performs some operation.
  638.  
  639. Input stream
  640.      A continuous flow of data between devices or programs.
  641.  
  642. Language construct
  643.      One of the typical usage schemas of the language.  For example,
  644.      one of the constructs of the C language is the `if' statement.
  645.      *Note Language and Grammar::.
  646.  
  647. Left associativity
  648.      Operators having left associativity are analyzed from left to
  649.      right: `a+b+c' first computes `a+b' and then combines with `c'. 
  650.      *Note Precedence::.
  651.  
  652. Left recursion
  653.      A rule whose result symbol is also its first component symbol; for
  654.      example, `expseq1 : expseq1 ',' exp;'.  *Note Recursion::.
  655.  
  656. Left-to-right parsing
  657.      Parsing a sentence of a language by analyzing it token by token
  658.      from left to right.  *Note Algorithm::.
  659.  
  660. Lexical analyzer (scanner)
  661.      A function that reads an input stream and returns tokens one by
  662.      one. *Note Lexical::.
  663.  
  664. Lexical tie-in
  665.      A flag, set by actions in the grammar rules, which alters the way
  666.      tokens are parsed.  *Note Lexical Tie-ins::.
  667.  
  668. Look-ahead token
  669.      A token already read but not yet shifted.  *Note Look-Ahead::.
  670.  
  671. LALR(1)
  672.      The class of context-free grammars that Bison (like most other
  673.      parser generators) can handle; a subset of LR(1).  *Note 
  674.      Mysterious Reduce/Reduce Conflicts: Mystery Conflicts.
  675.  
  676. LR(1)
  677.      The class of context-free grammars in which at most one token of
  678.      look-ahead is needed to disambiguate the parsing of any piece of
  679.      input.
  680.  
  681. Nonterminal symbol
  682.      A grammar symbol standing for a grammatical construct that can be
  683.      expressed through rules in terms of smaller constructs; in other
  684.      words, a construct that is not a token.  *Note Symbols::.
  685.  
  686. Parse error
  687.      An error encountered during parsing of an input stream due to
  688.      invalid syntax.  *Note Error Recovery::.
  689.  
  690. Parser
  691.      A function that recognizes valid sentences of a language by
  692.      analyzing the syntax structure of a set of tokens passed to it
  693.      from a lexical analyzer.
  694.  
  695. Postfix operator
  696.      An arithmetic operator that is placed after the operands upon
  697.      which it performs some operation.
  698.  
  699. Reduction
  700.      Replacing a string of nonterminals and/or terminals with a single
  701.      nonterminal, according to a grammar rule.  *Note Algorithm::.
  702.  
  703. Reentrant
  704.      A reentrant subprogram is a subprogram which can be in invoked any
  705.      number of times in parallel, without interference between the
  706.      various invocations.  *Note Pure Decl::.
  707.  
  708. Reverse polish notation
  709.      A language in which all operators are postfix operators.
  710.  
  711. Right recursion
  712.      A rule whose result symbol is also its last component symbol; for
  713.      example, `expseq1: exp ',' expseq1;'.  *Note Recursion::.
  714.  
  715. Semantics
  716.      In computer languages, the semantics are specified by the actions
  717.      taken for each instance of the language, i.e., the meaning of each
  718.      statement.  *Note Semantics::.
  719.  
  720. Shift
  721.      A parser is said to shift when it makes the choice of analyzing
  722.      further input from the stream rather than reducing immediately some
  723.      already-recognized rule.  *Note Algorithm::.
  724.  
  725. Single-character literal
  726.      A single character that is recognized and interpreted as is. *Note
  727.      Grammar in Bison::.
  728.  
  729. Start symbol
  730.      The nonterminal symbol that stands for a complete valid utterance
  731.      in the language being parsed.  The start symbol is usually listed
  732.      as the first nonterminal symbol in a language specification. 
  733.      *Note Start Decl::.
  734.  
  735. Symbol table
  736.      A data structure where symbol names and associated data are stored
  737.      during parsing to allow for recognition and use of existing
  738.      information in repeated uses of a symbol.  *Note Multi-function
  739.      Calc::.
  740.  
  741. Token
  742.      A basic, grammatically indivisible unit of a language.  The symbol
  743.      that describes a token in the grammar is a terminal symbol. The
  744.      input of the Bison parser is a stream of tokens which comes from
  745.      the lexical analyzer.  *Note Symbols::.
  746.  
  747. Terminal symbol
  748.      A grammar symbol that has no rules in the grammar and therefore is
  749.      grammatically indivisible.  The piece of text it represents is a
  750.      token.  *Note Language and Grammar::.
  751.  
  752. File: bison.info,  Node: Index,  Prev: Glossary,  Up: top
  753.  
  754. Index
  755. *****
  756.  
  757. * Menu:
  758.  
  759. * $$:                                   Actions.
  760. * $N:                                   Actions.
  761. * %expect:                              Expect Decl.
  762. * %left:                                Using Precedence.
  763. * %nonassoc:                            Using Precedence.
  764. * %prec:                                Contextual Precedence.
  765. * %pure_parser:                         Pure Decl.
  766. * %right:                               Using Precedence.
  767. * %start:                               Start Decl.
  768. * %token:                               Token Decl.
  769. * %type:                                Type Decl.
  770. * %union:                               Union Decl.
  771. * @N:                                   Action Features.
  772. * calc:                                 Infix Calc.
  773. * else, dangling:                       Shift/Reduce.
  774. * mfcalc:                               Multi-function Calc.
  775. * rpcalc:                               RPN Calc.
  776. * BNF:                                  Language and Grammar.
  777. * Backus-Naur form:                     Language and Grammar.
  778. * Bison declaration summary:            Decl Summary.
  779. * Bison declarations:                   Declarations.
  780. * Bison declarations (introduction):    Bison Declarations.
  781. * Bison grammar:                        Grammar in Bison.
  782. * Bison invocation:                     Invocation.
  783. * Bison parser:                         Bison Parser.
  784. * Bison parser algorithm:               Algorithm.
  785. * Bison symbols, table of:              Table of Symbols.
  786. * Bison utility:                        Bison Parser.
  787. * C code, section for additional:       C Code.
  788. * C declarations section:               C Declarations.
  789. * C-language interface:                 Interface.
  790. * LALR(1):                              Mystery Conflicts.
  791. * LR(1):                                Mystery Conflicts.
  792. * VMS:                                  VMS Invocation.
  793. * YYABORT:                              Parser Function.
  794. * YYACCEPT:                             Parser Function.
  795. * YYBACKUP:                             Action Features.
  796. * YYDEBUG:                              Debugging.
  797. * YYEMPTY:                              Action Features.
  798. * YYERROR:                              Action Features.
  799. * YYINITDEPTH:                          Stack Overflow.
  800. * YYLTYPE:                              Token Positions.
  801. * YYMAXDEPTH:                           Stack Overflow.
  802. * YYPRINT:                              Debugging.
  803. * YYRECOVERING:                         Error Recovery.
  804. * action:                               Actions.
  805. * action data types:                    Action Types.
  806. * action features summary:              Action Features.
  807. * actions in mid-rule:                  Mid-Rule Actions.
  808. * actions, semantic:                    Semantic Actions.
  809. * additional C code section:            C Code.
  810. * algorithm of parser:                  Algorithm.
  811. * associativity:                        Why Precedence.
  812. * calculator, infix notation:           Infix Calc.
  813. * calculator, multi-function:           Multi-function Calc.
  814. * calculator, simple:                   RPN Calc.
  815. * character token:                      Symbols.
  816. * compiling the parser:                 Rpcalc Compile.
  817. * conflicts:                            Shift/Reduce.
  818. * conflicts, reduce/reduce:             Reduce/Reduce.
  819. * conflicts, suppressing warnings of:   Expect Decl.
  820. * context-dependent precedence:         Contextual Precedence.
  821. * context-free grammar:                 Language and Grammar.
  822. * controlling function:                 Rpcalc Main.
  823. * dangling else:                        Shift/Reduce.
  824. * data types in actions:                Action Types.
  825. * data types of semantic values:        Value Type.
  826. * debugging:                            Debugging.
  827. * declaration summary:                  Decl Summary.
  828. * declarations, Bison:                  Declarations.
  829. * declarations, Bison (introduction):   Bison Declarations.
  830. * declarations, C:                      C Declarations.
  831. * declaring operator precedence:        Precedence Decl.
  832. * declaring the start symbol:           Start Decl.
  833. * declaring token type names:           Token Decl.
  834. * declaring value types:                Union Decl.
  835. * declaring value types, nonterminals:  Type Decl.
  836. * defining language semantics:          Semantics.
  837. * error:                                Error Recovery.
  838. * error recovery:                       Error Recovery.
  839. * error recovery, simple:               Simple Error Recovery.
  840. * error reporting function:             Error Reporting.
  841. * error reporting routine:              Rpcalc Error.
  842. * examples, simple:                     Examples.
  843. * exercises:                            Exercises.
  844. * file format:                          Grammar Layout.
  845. * finite-state machine:                 Parser States.
  846. * formal grammar:                       Grammar in Bison.
  847. * format of grammar file:               Grammar Layout.
  848. * glossary:                             Glossary.
  849. * grammar file:                         Grammar Layout.
  850. * grammar rule syntax:                  Rules.
  851. * grammar rules section:                Grammar Rules.
  852. * grammar, Bison:                       Grammar in Bison.
  853. * grammar, context-free:                Language and Grammar.
  854. * grouping, syntactic:                  Language and Grammar.
  855. * infix notation calculator:            Infix Calc.
  856. * interface:                            Interface.
  857. * introduction:                         Introduction.
  858. * invoking Bison:                       Invocation.
  859. * invoking Bison under VMS:             VMS Invocation.
  860. * language semantics, defining:         Semantics.
  861. * layout of Bison grammar:              Grammar Layout.
  862. * left recursion:                       Recursion.
  863. * lexical analyzer:                     Lexical.
  864. * lexical analyzer, purpose:            Bison Parser.
  865. * lexical analyzer, writing:            Rpcalc Lexer.
  866. * lexical tie-in:                       Lexical Tie-ins.
  867. * literal token:                        Symbols.
  868. * look-ahead token:                     Look-Ahead.
  869. * main function in simple example:      Rpcalc Main.
  870. * mid-rule actions:                     Mid-Rule Actions.
  871. * multi-function calculator:            Multi-function Calc.
  872. * mutual recursion:                     Recursion.
  873. * nonterminal symbol:                   Symbols.
  874. * operator precedence:                  Precedence.
  875. * operator precedence, declaring:       Precedence Decl.
  876. * options for invoking Bison:           Invocation.
  877. * overflow of parser stack:             Stack Overflow.
  878. * parse error:                          Error Reporting.
  879. * parser:                               Bison Parser.
  880. * parser stack:                         Algorithm.
  881. * parser stack overflow:                Stack Overflow.
  882. * parser state:                         Parser States.
  883. * polish notation calculator:           RPN Calc.
  884. * precedence declarations:              Precedence Decl.
  885. * precedence of operators:              Precedence.
  886. * precedence, context-dependent:        Contextual Precedence.
  887. * precedence, unary operator:           Contextual Precedence.
  888. * preventing warnings about conflicts:  Expect Decl.
  889. * pure parser:                          Pure Decl.
  890. * recovery from errors:                 Error Recovery.
  891. * recursive rule:                       Recursion.
  892. * reduce/reduce conflict:               Reduce/Reduce.
  893. * reduction:                            Algorithm.
  894. * reentrant parser:                     Pure Decl.
  895. * reverse polish notation:              RPN Calc.
  896. * right recursion:                      Recursion.
  897. * rule syntax:                          Rules.
  898. * rules section for grammar:            Grammar Rules.
  899. * running Bison (introduction):         Rpcalc Gen.
  900. * semantic actions:                     Semantic Actions.
  901. * semantic value:                       Semantic Values.
  902. * semantic value type:                  Value Type.
  903. * shift/reduce conflicts:               Shift/Reduce.
  904. * shifting:                             Algorithm.
  905. * simple examples:                      Examples.
  906. * single-character literal:             Symbols.
  907. * stack overflow:                       Stack Overflow.
  908. * stack, parser:                        Algorithm.
  909. * stages in using Bison:                Stages.
  910. * start symbol:                         Language and Grammar.
  911. * start symbol, declaring:              Start Decl.
  912. * state (of parser):                    Parser States.
  913. * summary, Bison declaration:           Decl Summary.
  914. * summary, action features:             Action Features.
  915. * suppressing conflict warnings:        Expect Decl.
  916. * symbol:                               Symbols.
  917. * symbol table example:                 Mfcalc Symtab.
  918. * symbols (abstract):                   Language and Grammar.
  919. * symbols in Bison, table of:           Table of Symbols.
  920. * syntactic grouping:                   Language and Grammar.
  921. * syntax error:                         Error Reporting.
  922. * syntax of grammar rules:              Rules.
  923. * terminal symbol:                      Symbols.
  924. * token:                                Language and Grammar.
  925. * token type:                           Symbols.
  926. * token type names, declaring:          Token Decl.
  927. * tracing the parser:                   Debugging.
  928. * unary operator precedence:            Contextual Precedence.
  929. * using Bison:                          Stages.
  930. * value type, semantic:                 Value Type.
  931. * value types, declaring:               Union Decl.
  932. * value types, nonterminals, declaring: Type Decl.
  933. * value, semantic:                      Semantic Values.
  934. * warnings, preventing:                 Expect Decl.
  935. * writing a lexical analyzer:           Rpcalc Lexer.
  936. * yychar:                               Look-Ahead.
  937. * yyclearin:                            Error Recovery.
  938. * yydebug:                              Debugging.
  939. * yyerrok:                              Error Recovery.
  940. * yyerror:                              Error Reporting.
  941. * yylex:                                Lexical.
  942. * yylloc:                               Token Positions.
  943. * yylval:                               Token Values.
  944. * yynerrs:                              Error Reporting.
  945. * yyparse:                              Parser Function.
  946. * |:                                    Rules.
  947.  
  948.  
  949.